package com.pe1n.yangtaopai.page.search.presenter;

import com.pe1n.yangtaopai.bean.HotBean;
import com.pe1n.yangtaopai.bean.SearchBean;
import com.pe1n.yangtaopai.page.search.modle.IModle;
import com.pe1n.yangtaopai.page.search.modle.ModleImpl;
import com.pe1n.yangtaopai.page.search.view.interfacese.IView;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Pe1n on 2016/11/28.
 */

public class PresenterImpl implements IPresenter {

    private IModle mModle;
    private IView mView;

    public PresenterImpl(IView mView) {
        this.mView = mView;
        this.mModle = new ModleImpl();
    }

    @Override
    public void loadHotBeanData(String url) {
        mModle.getHotBean(url)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<HotBean>() {
                    @Override
                    public void onCompleted() {
                        mView.hideProgress();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HotBean hotBean) {
                        mView.loadHotBean(hotBean);
                    }
                });
    }

    @Override
    public void loadSearchBeanData(String url) {
        mModle.getSearchBean(url)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<SearchBean>() {
                    @Override
                    public void onCompleted() {
                        mView.hideProgress();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(SearchBean searchBean) {
                        mView.loadSearchBean(searchBean);
                    }
                });
    }
}
